﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SemenQuest.Communication
{
    public class Conversation
    {
        private List<Message> Messages { get; set; }
        public Guid Participant { get; private set; }


        public Conversation(Guid participant)
        {
            Messages = new List<Message>();
            this.Participant = participant;
        }


        public void AddMessage(Message message)
        {
            Messages.Add(message);
        }
        public Message this[Int32 x]
        {
            get
            {                
                return Messages[x];
            }
        }
        public Message ReturnNewest()
        {
            if (Messages.Count > 0)
            {
                return Messages[Messages.Count - 1];
            }
            return null;
        }
        public Boolean TryGetnewest(out Message message)
        {
            if (Messages.Count > 0)
            {
                message = Messages[Messages.Count - 1];
                return true;
            }
            message = null;
            return false;
        }


        public int Length { get { return Messages.Count; } }
    }
}
